#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<string>

using namespace std;

string ReverseString(string s, int k)
{
	int i = 0;
	for (i = 0; i < s.size(); i += 2 * k)
	{	
		int start = i;
		int end = start + k - 1;
		if (s.size() - i < k)
		{	
			end = s.size() - 1;
		}
		while (start < end)
		{
			char temp = s[start];
			s[start] = s[end];
			s[end] = temp;
			++start;
			--end;
		}
	}
	return s;
}

int main()
{
	string s;
	int k = 0;
	getline(cin, s);
	cin >> k;
	cout << s << endl;
	cout << ReverseString(s, k) << endl;
	return 0;
}